import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

import '../size_config.dart';

class RoundedButton extends StatefulWidget {
  const RoundedButton({
    Key? key,
    // this.size = 64,
    this.size = 80,
    required this.iconSrc,
    this.color = Colors.white,
    this.iconColor = Colors.black,
    required this.press,
  }) : super(key: key);

  final double size;
  final String iconSrc;
  final Color color, iconColor;
  final VoidCallback press;

  @override
  State<RoundedButton> createState() => _RoundedButtonState();
}

class _RoundedButtonState extends State<RoundedButton> {
  late double size;
  late String iconSrc;
  late Color color;
  late Color iconColor;
  bool toggle = false;

  @override
  void initState() {
    super.initState();
    size = widget.size;
    iconSrc = widget.iconSrc;
    color = widget.color;
    iconColor = widget.iconColor;
  }

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: getProportionateScreenWidth(size),
      width: getProportionateScreenWidth(size),
      child: ElevatedButton(
        style: ButtonStyle(
            backgroundColor: MaterialStateProperty.all(color),
            padding: MaterialStateProperty.all(EdgeInsets.all(15 / 64 * size)),
            shape: MaterialStateProperty.all(
              const RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(100)),
              ),
            )),
        onPressed: () {
          widget.press.call();
          setState(() {
            if (toggle) {
              color = widget.color;
              iconColor = widget.iconColor;
              toggle = false;
            } else {
              color = Colors.grey;
              iconColor = Colors.white;
              toggle = true;
            }
          });
        },
        child: SvgPicture.asset(
          iconSrc,
          colorFilter: ColorFilter.mode(iconColor, BlendMode.srcIn),
        ),
      ),
    );
  }
}
